using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Csla;

namespace Model
{
    [Serializable()]
    public class ViTriBOList : Csla.NameValueListBase<int?, string>
    {
        #region Factory Methods
        private ViTriBOList()
        {
        }

        public void InsertCustomValue(int? customKey, string customValue)
        {
            IsReadOnly = false;
            this.Insert(0, new NameValuePair(customKey, customValue));
            IsReadOnly = true;
        }

        public void InsertCustomValue(int index, int? customKey, string customValue)
        {
            IsReadOnly = false;
            this.Insert(index, new NameValuePair(customKey, customValue));
            IsReadOnly = true;
        }

        public void AddCustomValue(int? customKey, string customValue)
        {
            IsReadOnly = false;
            this.Add(new NameValuePair(customKey, customValue));
            IsReadOnly = true;
        }

        public void CleaAll()
        {
            IsReadOnly = false;
            this.ClearItems();
            IsReadOnly = true;
        }

        private static ViTriBOList _list;

        public static ViTriBOList NewViTriBOList()
        {
            _list = DataPortal.Fetch<ViTriBOList>(true);
            return _list;
        }

        public static ViTriBOList GetViTriBOList()
        {
            _list = DataPortal.Fetch<ViTriBOList>(null);
            return _list;
        }

        public static void InvalidateCache()
        {
            _list = null;
        }
        #endregion Factory Methods
        //==========================================================================

        #region Data Access
        protected override void DataPortal_Fetch(object _spParam)
        {
            if (_spParam == null)
            {
                RaiseListChangedEvents = false;
                IsReadOnly = false;
                this.Add(new NameValuePair(0, ""));
                this.Add(new NameValuePair(1, "1"));
                this.Add(new NameValuePair(2, "2"));
                this.Add(new NameValuePair(3, "3"));
                this.Add(new NameValuePair(4, "4"));
                this.Add(new NameValuePair(5, "5"));
                IsReadOnly = true;
                RaiseListChangedEvents = true;
            }
        }
        #endregion Data Access
        //==========================================================================
    }
}
